//
//  HZProductTextImageDetailModel.m
//  app
//
//  Created by 刘华舟 on 15/6/3.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZProductTextImageDetailModel.h"



@implementation HZProductTextImageDetailModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dict{
    return [[HZProductTextImageDetailModel alloc] initModelWithDictionary:dict];
}

- (instancetype)initModelWithDictionary:(NSDictionary *)dict{
    if (self = [super init]) {
        _title = [dict stringForKey:APIKEY_mall_title nilValue:@""];
        _pic = [dict stringForKey:APIKEY_mall_pic nilValue:@""];
        _width = [dict stringForKey:APIKEY_mall_width nilValue:@"1"];
        if (![_width boolValue]) {
            _width = @"1";
        }
        _height = [dict stringForKey:APIKEY_mall_height nilValue:@"1"];
        if (![_height boolValue]) {
            _height = @"1";
        }
        _text = [dict stringForKey:APIKEY_mall_text nilValue:@""];
       
        
        _cellHeight = [UBO_SCREEN uh:0];
        
        
        if (_title.length) {
            
            _cellHeight += [UBO_SCREEN uh:kProductTextImageDetailTitleLabelHeight];
        }
        
        if (_pic.length) {
            _cellHeight = _cellHeight+6+[UBO_SCREEN fw:UB_WIDTH uw:-(kSizeMallViewMargin*2)]*[_height floatValue]/[_width floatValue];
        }
        
        if (_text.length) {
            CGSize contentTextSize = [_text boundingRectWithSize:[UBO_SCREEN fw:UB_WIDTH uw:-(kSizeMallViewMargin*2) uh:kProductTextImageDetailTextMaxHeight] options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:JKAppGlobleFontSmallTagText} context:nil].size;
            
            
            _cellHeight += contentTextSize.height + [UBO_SCREEN uh:kSizeMallViewMargin];
        }
        
        
    }
    return self;
}

@end
